from flask import Flask, jsonify, Response
from cfg.repo.json_response import JsonResponse


class JsonFlask(Flask):
    def make_response(self, rv):
        """
        视图函数可以直接返回: list、dict、None
        """
        if not isinstance(rv, Response):
            if not isinstance(rv, JsonResponse):
                rv = JsonResponse.success(rv)
            if isinstance(rv, JsonResponse):
                rv = jsonify(rv.to_dict())

        return super().make_response(rv)
